<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="model.WeiGui"%>
<%@ page import="dao.WeiGuiDao"%>
<%@ page import="java.util.List" %>

<%
	//检查会话中是否有 "student" 属性
	Object fdyObj = session.getAttribute("student");
	if (fdyObj == null) {
	    response.sendRedirect("../view/Login.jsp");
	    return;
	}
%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生页面</title>
<link href="../css/Utils.css" rel="stylesheet" type="text/css" />
<link href="../css/List.css" rel="stylesheet" type="text/css" />
<!-- 违规功能列表 -->
<link rel="stylesheet" href="../css/WeiGuilist.css">
<!-- 退出登录专用 -->
   <script type="text/javascript" src="../view/Loginout.js"></script>
</head>
<body>

<!-- 头部 -->
<div class="header" ><br>
<nerong>&nbsp;&nbsp;学生页面&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;</nerong>

 <button onclick="confirmLogout('<%= (String)session.getAttribute("student") %>','student')">退出登录</button>

</div><br>

<div class="left" >
<table width="80%" height="80%">
<th>
<nerong>学生可选择内容</nerong>

</th>

<tr>
<td>
<a href="../View_Msg/msgStudent.jsp">&emsp;个人信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_SuShe/SuSheStudent.jsp">&emsp;宿舍信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_fix/StudentFix.jsp">&emsp;宿舍报修</a><br>
</td>
</tr>


<tr>
<td>
<a href = "WeiGuiStudent.jsp">&emsp;违规消息查询</a><br>
</td>
</tr>

<tr>
<td>
<a href = "../View_leave/S_Main_Leave.jsp">&emsp;请假</a><br>
</td>
</tr>

</table>

</div>



<div class="context">
<!-- 这部分是每个大功能的小功能 -->
	 <h2>违规情况</h2>
		<table class="Alltable">
        <thead>
            <tr>
                <th>学号</th>
                <th>时间</th>
                <th>类型</th>
                <th>原因</th>
            </tr>
        </thead>
        <tbody>
            <%
            // 获取当前页（默认第一页）
            int currentPage = 1;
            int pageSize = 9;  // 每页显示5条记录
            String pageParam = request.getParameter("page");//至今为止不知道在哪设的
            String id = (String)session.getAttribute("student");
            if (pageParam != null && !pageParam.isEmpty()) {
                currentPage = Integer.parseInt(pageParam);
            }
            
            WeiGuiDao dao = new WeiGuiDao();
                // 获取总记录数
                int totalUsers = dao.getStudentCount(id);
                // 计算总页数
                int totalPages = (int) Math.ceil((double) totalUsers / pageSize);
                // 获取当前页的数据
                List<WeiGui> wgs = dao.getWGStudentPage(id,currentPage, pageSize);
                for (WeiGui wg : wgs) {
            %>
            <tr>
                <td><%= wg.getId() %></td>
                <td><%= wg.getTime() %></td>
                <td><%= wg.getType() %></td>
                <td><%= wg.getBecause() %></td>
             	
            </tr>
            
            <%
                
                }
            %>
           
           	
            
        </tbody>
    </table>
     <!-- 分页显示 -->
    <div>
        <% if (currentPage > 1) { %>
            <a href="WeiGuiStudent.jsp?page=<%= currentPage - 1 %>">上一页</a>
        <% } %>
        <span>页 <%= currentPage %> / <%= totalPages %></span>
        <% if (currentPage < totalPages) { %>
            <a href="WeiGuiStudent.jsp?page=<%= currentPage + 1 %>">下一页</a>
        <% } %>
    </div>
</div>

</body>
</html>